import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_learn_vi/src/net/dio_utils.dart';
import 'package:flutter_learn_vi/src/utils/navigator_utils.dart';
import 'package:flutter_learn_vi/src/utils/toast_utils.dart';

/// 创建人： Created by zhaolong
/// 创建时间：Created by  on 2020/12/11.
///
/// 可关注公众号：我的大前端生涯   获取最新技术分享
/// 可关注网易云课堂：https://study.163.com/instructor/1021406098.htm
/// 可关注博客：https://blog.csdn.net/zl18603543572
///
/// 代码清单
///代码清单
class FaceBackPage extends StatefulWidget {
  final int pageIndex;

  FaceBackPage(this.pageIndex);

  @override
  _FaceBackPageState createState() => _FaceBackPageState();
}

class _FaceBackPageState extends State<FaceBackPage> {
  TextEditingController _editingController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.pageIndex == 1 ? "领导信箱" : "职工建议"),
      ),

      ///填充布局
      body: Container(
          color: Colors.white,
          width: double.infinity,
          height: 300,
          child: Column(
            children: [
              Container(
                padding: EdgeInsets.all(12),
                child: TextField(
                  controller: _editingController,
                  maxLength: 200,
                  maxLines: 8,
                  style: TextStyle(),
                  decoration: InputDecoration(
                      hintText: "请输入您要反馈的信息", border: OutlineInputBorder()),
                ),
              ),
              Align(
                child: Container(
                  width: 100,
                  margin: EdgeInsets.only(right: 12),
                  child: ElevatedButton(
                    onPressed: () {
                      String text = _editingController.text;
                      if (text.length == 0) {
                        String message = widget.pageIndex == 2
                            ? "请输入您的建议和意见！"
                            : "请输入您的来信内容！";
                        ToastUtils.showToast(message);
                        return;
                      }
                      commitNetDataFunction(text);
                    },
                    child: Text("提交"),
                  ),
                ),
                alignment: Alignment.centerRight,
              ),
            ],
          )),
    );
  }

  void commitNetDataFunction(String text) async {
    Map<String, dynamic> map = {
      "content": text,
    };
    String url = HttpHelper.barmasterletterbox;
    if (widget.pageIndex == 2) {
      url = HttpHelper.masssuggestion;
    }
    ResponseInfo partResponseInfo = await DioUtils.instance.postRequest(
      url: url,
      jsonMap: map,
    );
    ToastUtils.showToast("已收到您的反馈");
    Future.delayed(Duration(milliseconds: 1200), () {
      NavigatorUtils.pop(context);
    });
  }
}
